<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" class="form-inline">
        <el-button v-waves class="filter-item" type="primary" icon="el-icon-edit" @click="handleEditSetting">编辑平台枚举</el-button>
      </el-form>
      <el-dialog :visible.sync="editFormVisible" title="平台枚举配置">
        <el-form>
          <el-form-item label="JSON:" >
            <el-input
              :autosize="{ minRows: 10,maxRows: 20}"
              v-model="settingJson"
              type="textarea"
              width="800"
              placeholder=""/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="editFormVisible = false">取 消</el-button>
          <el-button v-loading.fullscreen.lock="fullscreenLoading" type="primary" @click="handleSaveSetting">确 定</el-button>
        </div>
      </el-dialog>

    </div>

  </div>
</template>

<script>
import waves from '@/directive/waves'
import { loadSetting, saveSetting } from '@/api/settings.js'
export default {
  name: 'Settings',
  directives: { waves },
  components: { },
  data() {
    return {
      fullscreenLoading: false,
      editFormVisible: false,
      settingJson: ''
    }
  },
  created() {
  },
  methods: {
    handleEditSetting() {
      loadSetting().then(response => {
        if (response.code === '0000') {
          this.settingJson = response.data
          this.editFormVisible = true
        }
      })
    },
    handleSaveSetting() {
      this.fullscreenLoading = true
      saveSetting(JSON.parse(this.settingJson)).then(response => {
        if (response.code === '0000') {
          this.$message.success('保存平台枚举设置成功!')
          this.editFormVisible = false
        } else {
          this.$message.error('error:' + response.msg)
        }
        this.fullscreenLoading = false
      })
    }
  }
}
</script>
<style>
</style>

